using UnityEngine;  
using System.Collections; 
using System;
using System.IO;
using System.Text;
using UnityEditor;  
using System.Collections.Generic;
using System.Xml;
using System.Xml.Linq;


namespace AudioStudio
{
    public class AudioUtility
    {


        public static string GetXmlProperty(XElement node, string key)
        {
            var s = node.Descendants(key);
            if(s != null)
            {
                foreach(var i in s)
                {
                    return i.Value;
                }
            }
            return string.Empty;
        }

        public static int GetXmlPropertyAsInteger(XElement node, string key)
        {
            var s = node.Descendants(key);
            if(s != null)
            {
                int outValue = 0;
                foreach(var i in s)
                {
                    int.TryParse(i.Value, out outValue);
                    return outValue;
                }
            }
            return 0;
        }

        public static bool IsSoundAnimationEvent(UnityEngine.AnimationEvent animationEvent)
        {
            foreach (var method in typeof(AnimationSound).GetMethods())
            {
                if(method.IsPublic)
                {
                    if (animationEvent.functionName == method.Name)
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public static string Combine(string a,string b)
        {
            return Path.Combine(a,b).Replace('\\','/');
        }

        public static AkWwiseProjectData.Event FindEvent(Guid guid)
        {
            var EventWwu = AkWwiseProjectInfo.GetData().EventWwu;

            for (int i = 0; i < EventWwu.Count; i++)
            {
                var e = EventWwu[i].List.Find(x => new Guid(x.Guid.ToByteArray()).Equals(guid));
                if (e != null)
                {
                    return e;
                }
            }
            return null;
        }

        public static AkWwiseProjectData.Event FindEvent(string eventName)
        {
            var EventWwu = AkWwiseProjectInfo.GetData().EventWwu;

            for (int i = 0; i < EventWwu.Count; i++)
            {
                var e = EventWwu[i].List.Find(x => x.Name.Equals(eventName));
                if (e != null)
                {
                    return e;
                }
            }
            return null;
        }
    }
}